package protagonist.common.pojo;

import lombok.Data;
import protagonist.common.pojo.constant.CommonConstant;

import java.io.Serializable;

/**
 * 通用返回
 *
 * @param <T> 数据泛型
 */
@Data
public class CommonResult<T> implements Serializable {

    /**
     * 错误码
     *
     */
    private Integer code;
    /**
     * 返回数据
     */
    private T data;
    /**
     * 错误提示，用户可阅读
     *
     */
    private String msg;

    public static <T> CommonResult<T> success(T t) {
        CommonResult<T> commonResult = new CommonResult<T>();
        commonResult.setCode(0);
        commonResult.setData(t);
        commonResult.setMsg(CommonConstant.success);
        return commonResult;
    }

    public static <T> CommonResult<T> error() {
        CommonResult<T> commonResult = new CommonResult<T>();
        commonResult.setCode(0);
        commonResult.setMsg(CommonConstant.error);
        return commonResult;
    }
}
